home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / shutdo.zip / SHUTDOWN.C < prev    next >
C/C++ Source or Header  |  1993-06-29  |  2KB  |  63 lines

  1. //
  2. // Shutdown - utility
  3. // ==================
  4. // 
  5. // Programm Shutdown.exe
  6. // 
  7. // Parameter R:             loest einen Neustart aus
  8. // ohne Parameter:            normaler Shutdown
  9. // Mit anderem Parameter:        Hilfe
  10. //
  11.  
  12. #include <windows.h>
  13. #include <stdio.h>
  14.  
  15.  
  16. void main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20. HANDLE hToken;
  21. TOKEN_PRIVILEGES tkp;
  22. CHAR buffer[80];
  23.  
  24. /* Get the Process Token */
  25. if (!OpenProcessToken(GetCurrentProcess(),
  26.    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
  27.    printf ( buffer, "OpenProcessToken Error #%d", GetLastError ());
  28.    }
  29. /* Get the LUID for shutdown privilege */
  30.  
  31.    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
  32.              &tkp.Privileges[0].Luid);
  33.  
  34.    tkp.PrivilegeCount = 1;  /* one privilege to set    */
  35.    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  36.  
  37. /* Get shutdown privilege for this process. */
  38.  
  39.     if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  40.            (PTOKEN_PRIVILEGES)NULL, 0)) {
  41.     printf ( buffer, "AdjustTokenPrivileges Error #%d", GetLastError ());
  42.     }
  43.                 
  44. if (argc<2) 
  45.   {InitiateSystemShutdown(NULL, NULL, 0, FALSE, FALSE);
  46.   exit(1);}
  47. if ((argv[1][0]== 114) || (argv[1][0]== 82)){
  48.   InitiateSystemShutdown(NULL, NULL, 0, FALSE, TRUE);
  49.   exit(1);}
  50. if ((argv[1][0]== 102) || (argv[1][0]== 70)){
  51.   InitiateSystemShutdown(NULL, NULL, 0, TRUE, TRUE);
  52.   exit(1);}
  53. printf("Shutdown - Utility V. 1.01 \n");
  54. printf("shutdown   - Shutdown without reboot\n");
  55. printf("shutdown r - Shutdown with reboot\n");
  56. printf("shutdown f - FORCED Shutdown with reboot\n");
  57. printf("This utility may be freely distributed as long as it remains unchanged.\n");
  58. printf("Please forward suggestions to Martin Sieber (100142,2756)\n");;
  59. printf("Dedicated to the Windows NT community\n");
  60.  
  61. }
  62.  
  63.